﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tank.Properties;
namespace Tank
{
    class PlayerTank : TankFather
    {
        private static Image[] imgs = { 
                              Resources.p1tankU,
                              Resources.p1tankD,
                              Resources.p1tankL,
                              Resources.p1tankR
                               };

        public PlayerTank(int x, int y, int speed, int life, Direction dir)
            : base(x, y, imgs, speed, life, dir)
        {
            Born();
        }

        public int ZDLevel
        {
            get;
            set;
        }


        public override void Born()
        {
            SingleObject.GetSingle().AddGameObject(new TankBorn(this.X, this.Y));
        }

        public void KeyDown(KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.W:
                    this.Dir = Direction.Up;
                    base.Move();
                    break;
                case Keys.S:
                    this.Dir = Direction.Down;
                    base.Move();
                    break;
                case Keys.A:
                    this.Dir = Direction.Left;
                    base.Move();
                    break;
                case Keys.D:
                    this.Dir = Direction.Right;
                    base.Move();
                    break;
                case Keys.Space:
                    Fire();
                    break;
            }
        }


        public override void Fire()
        {
            switch (ZDLevel)
            {
                case 0: SingleObject.GetSingle().AddGameObject(new PlayerZD(this, 10, 10, 1));
                    break;
                case 1: SingleObject.GetSingle().AddGameObject(new PlayerZD(this, 20, 10, 1));
                    break;
                case 2: SingleObject.GetSingle().AddGameObject(new PlayerZD(this, 30, 10, 1));
                    break;
            }

        }


        public override void IsOver()
        {
            if (this.Life == 0)//被击中了并且死亡
            {
                //出现爆炸的图片
                SingleObject.GetSingle().AddGameObject(new Boom(this.X - 25, this.Y - 25));
                //被击中了 删除掉被击中的坦克
                SingleObject.GetSingle().RemoveGameObject(this);
                //播放坦克爆炸的声音
                SoundPlayer sp = new SoundPlayer(Resources.fire);
                sp.Play();

            }
            else//敌人被击中 但是没有死亡
            {
                SoundPlayer sp = new SoundPlayer(Resources.hit);
                sp.Play();
            }
        }

    }
}
